<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span id="local-6989586621679501764"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE StandaloneDeriving #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE PolyKinds, DataKinds, TypeFamilies, TypeOperators, UndecidableInstances #-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Module      :  Data.Either</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- The Either type, and associated operations.</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Either</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-22"></span><span>   </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier">Either</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>   </span><span class="annot"><a href="Data.Either.html#either"><span class="hs-identifier">either</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>   </span><span class="annot"><a href="Data.Either.html#lefts"><span class="hs-identifier">lefts</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>   </span><span class="annot"><a href="Data.Either.html#rights"><span class="hs-identifier">rights</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>   </span><span class="annot"><a href="Data.Either.html#isLeft"><span class="hs-identifier">isLeft</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>   </span><span class="annot"><a href="Data.Either.html#isRight"><span class="hs-identifier">isRight</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>   </span><span class="annot"><a href="Data.Either.html#fromLeft"><span class="hs-identifier">fromLeft</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>   </span><span class="annot"><a href="Data.Either.html#fromRight"><span class="hs-identifier">fromRight</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>   </span><span class="annot"><a href="Data.Either.html#partitionEithers"><span class="hs-identifier">partitionEithers</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Read.html"><span class="hs-identifier">GHC.Read</span></a></span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span class="hs-comment">-- $setup</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- Allow the use of some Prelude functions in doctests.</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- &gt;&gt;&gt; import Prelude ( (+), (*), length, putStrLn )</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span class="hs-comment">{-
-- just for testing
import Test.QuickCheck
-}</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-comment">{-|

The 'Either' type represents values with two possibilities: a value of
type @'Either' a b@ is either @'Left' a@ or @'Right' b@.

The 'Either' type is sometimes used to represent a value which is
either correct or an error; by convention, the 'Left' constructor is
used to hold an error value and the 'Right' constructor is used to
hold a correct value (mnemonic: \&quot;right\&quot; also means \&quot;correct\&quot;).

==== __Examples__

The type @'Either' 'String' 'Int'@ is the type of values which can be either
a 'String' or an 'Int'. The 'Left' constructor can be used only on
'String's, and the 'Right' constructor can be used only on 'Int's:

&gt;&gt;&gt; let s = Left &quot;foo&quot; :: Either String Int
&gt;&gt;&gt; s
Left &quot;foo&quot;
&gt;&gt;&gt; let n = Right 3 :: Either String Int
&gt;&gt;&gt; n
Right 3
&gt;&gt;&gt; :type s
s :: Either String Int
&gt;&gt;&gt; :type n
n :: Either String Int

The 'fmap' from our 'Functor' instance will ignore 'Left' values, but
will apply the supplied function to values contained in a 'Right':

&gt;&gt;&gt; let s = Left &quot;foo&quot; :: Either String Int
&gt;&gt;&gt; let n = Right 3 :: Either String Int
&gt;&gt;&gt; fmap (*2) s
Left &quot;foo&quot;
&gt;&gt;&gt; fmap (*2) n
Right 6

The 'Monad' instance for 'Either' allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
'Int' from a 'Char', or fail.

&gt;&gt;&gt; import Data.Char ( digitToInt, isDigit )
&gt;&gt;&gt; :{
    let parseEither :: Char -&gt; Either String Int
        parseEither c
          | isDigit c = Right (digitToInt c)
          | otherwise = Left &quot;parse error&quot;
&gt;&gt;&gt; :}

The following should work, since both @\'1\'@ and @\'2\'@ can be
parsed as 'Int's.

&gt;&gt;&gt; :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x &lt;- parseEither '1'
          y &lt;- parseEither '2'
          return (x + y)
&gt;&gt;&gt; :}

&gt;&gt;&gt; parseMultiple
Right 3

But the following should fail overall, since the first operation where
we attempt to parse @\'m\'@ as an 'Int' will fail:

&gt;&gt;&gt; :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x &lt;- parseEither 'm'
          y &lt;- parseEither '2'
          return (x + y)
&gt;&gt;&gt; :}

&gt;&gt;&gt; parseMultiple
Left &quot;parse error&quot;

-}</span><span>
</span><span id="line-125"></span><span class="hs-keyword">data</span><span>  </span><span id="Either"><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-var">Either</span></a></span></span><span> </span><span id="local-6989586621679501884"><span class="annot"><a href="#local-6989586621679501884"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621679501883"><span class="annot"><a href="#local-6989586621679501883"><span class="hs-identifier hs-type">b</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span id="Left"><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span></span><span> </span><span class="annot"><a href="#local-6989586621679501884"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="Right"><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span></span><span> </span><span class="annot"><a href="#local-6989586621679501883"><span class="hs-identifier hs-type">b</span></a></span><span>
</span><span id="line-126"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span> </span><span id="local-6989586621679501750"><span id="local-6989586621679501754"><span class="annot"><span class="annottext">Either a b -&gt; Either a b -&gt; Bool
(Either a b -&gt; Either a b -&gt; Bool)
-&gt; (Either a b -&gt; Either a b -&gt; Bool) -&gt; Eq (Either a b)
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
forall a b. (Eq a, Eq b) =&gt; Either a b -&gt; Either a b -&gt; Bool
/= :: Either a b -&gt; Either a b -&gt; Bool
$c/= :: forall a b. (Eq a, Eq b) =&gt; Either a b -&gt; Either a b -&gt; Bool
== :: Either a b -&gt; Either a b -&gt; Bool
$c== :: forall a b. (Eq a, Eq b) =&gt; Either a b -&gt; Either a b -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></a></span></span></span><span>   </span><span class="hs-comment">-- ^ @since 2.01</span><span>
</span><span id="line-127"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679501726"><span id="local-6989586621679501728"><span id="local-6989586621679501731"><span id="local-6989586621679501734"><span id="local-6989586621679501737"><span id="local-6989586621679501741"><span id="local-6989586621679501745"><span class="annot"><span class="annottext">Eq (Either a b)
Eq (Either a b)
-&gt; (Either a b -&gt; Either a b -&gt; Ordering)
-&gt; (Either a b -&gt; Either a b -&gt; Bool)
-&gt; (Either a b -&gt; Either a b -&gt; Bool)
-&gt; (Either a b -&gt; Either a b -&gt; Bool)
-&gt; (Either a b -&gt; Either a b -&gt; Bool)
-&gt; (Either a b -&gt; Either a b -&gt; Either a b)
-&gt; (Either a b -&gt; Either a b -&gt; Either a b)
-&gt; Ord (Either a b)
Either a b -&gt; Either a b -&gt; Bool
Either a b -&gt; Either a b -&gt; Ordering
Either a b -&gt; Either a b -&gt; Either a b
forall a.
Eq a
-&gt; (a -&gt; a -&gt; Ordering)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; a)
-&gt; (a -&gt; a -&gt; a)
-&gt; Ord a
forall {a} {b}. (Ord a, Ord b) =&gt; Eq (Either a b)
forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Bool
forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Ordering
forall a b.
(Ord a, Ord b) =&gt;
Either a b -&gt; Either a b -&gt; Either a b
min :: Either a b -&gt; Either a b -&gt; Either a b
$cmin :: forall a b.
(Ord a, Ord b) =&gt;
Either a b -&gt; Either a b -&gt; Either a b
max :: Either a b -&gt; Either a b -&gt; Either a b
$cmax :: forall a b.
(Ord a, Ord b) =&gt;
Either a b -&gt; Either a b -&gt; Either a b
&gt;= :: Either a b -&gt; Either a b -&gt; Bool
$c&gt;= :: forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Bool
&gt; :: Either a b -&gt; Either a b -&gt; Bool
$c&gt; :: forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Bool
&lt;= :: Either a b -&gt; Either a b -&gt; Bool
$c&lt;= :: forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Bool
&lt; :: Either a b -&gt; Either a b -&gt; Bool
$c&lt; :: forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Bool
compare :: Either a b -&gt; Either a b -&gt; Ordering
$ccompare :: forall a b. (Ord a, Ord b) =&gt; Either a b -&gt; Either a b -&gt; Ordering
</span><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Ord</span></a></span></span></span></span></span></span></span></span><span>  </span><span class="hs-comment">-- ^ @since 2.01</span><span>
</span><span id="line-128"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679501707"><span id="local-6989586621679501718"><span id="local-6989586621679501721"><span id="local-6989586621679501723"><span class="annot"><span class="annottext">ReadPrec [Either a b]
ReadPrec (Either a b)
Int -&gt; ReadS (Either a b)
ReadS [Either a b]
(Int -&gt; ReadS (Either a b))
-&gt; ReadS [Either a b]
-&gt; ReadPrec (Either a b)
-&gt; ReadPrec [Either a b]
-&gt; Read (Either a b)
forall a.
(Int -&gt; ReadS a)
-&gt; ReadS [a] -&gt; ReadPrec a -&gt; ReadPrec [a] -&gt; Read a
forall a b. (Read a, Read b) =&gt; ReadPrec [Either a b]
forall a b. (Read a, Read b) =&gt; ReadPrec (Either a b)
forall a b. (Read a, Read b) =&gt; Int -&gt; ReadS (Either a b)
forall a b. (Read a, Read b) =&gt; ReadS [Either a b]
readListPrec :: ReadPrec [Either a b]
$creadListPrec :: forall a b. (Read a, Read b) =&gt; ReadPrec [Either a b]
readPrec :: ReadPrec (Either a b)
$creadPrec :: forall a b. (Read a, Read b) =&gt; ReadPrec (Either a b)
readList :: ReadS [Either a b]
$creadList :: forall a b. (Read a, Read b) =&gt; ReadS [Either a b]
readsPrec :: Int -&gt; ReadS (Either a b)
$creadsPrec :: forall a b. (Read a, Read b) =&gt; Int -&gt; ReadS (Either a b)
</span><a href="GHC.Read.html#Read"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Read</span></a></span></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 3.0</span><span>
</span><span id="line-129"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679501694"><span id="local-6989586621679501696"><span id="local-6989586621679501703"><span class="annot"><span class="annottext">Int -&gt; Either a b -&gt; ShowS
[Either a b] -&gt; ShowS
Either a b -&gt; String
(Int -&gt; Either a b -&gt; ShowS)
-&gt; (Either a b -&gt; String)
-&gt; ([Either a b] -&gt; ShowS)
-&gt; Show (Either a b)
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
forall a b. (Show a, Show b) =&gt; Int -&gt; Either a b -&gt; ShowS
forall a b. (Show a, Show b) =&gt; [Either a b] -&gt; ShowS
forall a b. (Show a, Show b) =&gt; Either a b -&gt; String
showList :: [Either a b] -&gt; ShowS
$cshowList :: forall a b. (Show a, Show b) =&gt; [Either a b] -&gt; ShowS
show :: Either a b -&gt; String
$cshow :: forall a b. (Show a, Show b) =&gt; Either a b -&gt; String
showsPrec :: Int -&gt; Either a b -&gt; ShowS
$cshowsPrec :: forall a b. (Show a, Show b) =&gt; Int -&gt; Either a b -&gt; ShowS
</span><a href="GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 3.0</span><span>
</span><span id="line-130"></span><span>           </span><span class="hs-special">)</span><span>
</span><span id="line-131"></span><span>
</span><span id="line-132"></span><span class="hs-comment">-- | @since 3.0</span><span>
</span><span id="line-133"></span><span id="local-6989586621679501870"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679501690"><span class="annot"><a href="GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501870"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-134"></span><span>    </span><span id="local-6989586621679501688"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; Either a a -&gt; Either a b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679501687"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501687"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Either a b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501687"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-135"></span><span>    </span><span class="annot"><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span id="local-6989586621679501686"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679501686"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501685"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501685"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b -&gt; Either a b
forall a b. b -&gt; Either a b
</span><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679501686"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501685"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="hs-comment">-- | @since 4.9.0.0</span><span>
</span><span id="line-138"></span><span id="local-6989586621679501863"><span id="local-6989586621679501864"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679501680"><span id="local-6989586621679501682"><span class="annot"><a href="GHC.Base.html#Semigroup"><span class="hs-identifier hs-type">Semigroup</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501864"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501863"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-139"></span><span>    </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679501678"><span class="annot"><span class="annottext">&lt;&gt; :: Either a b -&gt; Either a b -&gt; Either a b
</span><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;&gt;</span></a></span></span><span> </span><span id="local-6989586621679501677"><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679501677"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679501677"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-140"></span><span>    </span><span id="local-6989586621679501676"><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679501676"><span class="hs-identifier hs-var">a</span></a></span></span><span>      </span><span class="annot"><a href="GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Either a b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679501676"><span class="hs-identifier hs-var">a</span></a></span></span></span><span class="hs-cpp">
#if !defined(__HADDOCK_VERSION__)
</span><span>    </span><span class="hs-comment">-- workaround https://github.com/haskell/haddock/issues/680</span><span>
</span><span id="line-143"></span><span>    </span><span class="hs-identifier">stimes</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-identifier">x</span><span>
</span><span id="line-144"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-operator">&lt;=</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">errorWithoutStackTrace</span><span> </span><span class="hs-string">&quot;stimes: positive multiplier expected&quot;</span><span>
</span><span id="line-145"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">x</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-148"></span><span class="hs-comment">-- | @since 3.0</span><span>
</span><span id="line-149"></span><span id="local-6989586621679501851"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679501666"><span id="local-6989586621679501668"><span id="local-6989586621679501670"><span class="annot"><a href="GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501851"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-150"></span><span>    </span><span id="local-6989586621679501664"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; Either e a
</span><a href="GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Either e a
forall a b. b -&gt; Either a b
</span><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span>
</span><span id="line-151"></span><span>    </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span id="local-6989586621679501662"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679501662"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span id="local-6989586621679501661"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. Either e (a -&gt; b) -&gt; Either e a -&gt; Either e b
</span><a href="GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;*&gt;</span></a></span></span><span> </span><span class="annot"><span class="annottext">Either e a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">e -&gt; Either e b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679501662"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-152"></span><span>    </span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501660"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679501660"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="annot"><a href="GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var">&lt;*&gt;</span></a></span><span> </span><span id="local-6989586621679501659"><span class="annot"><span class="annottext">Either e a
</span><a href="#local-6989586621679501659"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; Either e a -&gt; Either e b
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679501660"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Either e a
</span><a href="#local-6989586621679501659"><span class="hs-identifier hs-var">r</span></a></span></span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | @since 4.4.0.0</span><span>
</span><span id="line-155"></span><span id="local-6989586621679501841"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679501652"><span id="local-6989586621679501654"><span class="annot"><a href="GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501841"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-156"></span><span>    </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span id="local-6989586621679501650"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679501650"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679501649"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. Either e a -&gt; (a -&gt; Either e b) -&gt; Either e b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; Either e b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">e -&gt; Either e b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679501650"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-157"></span><span>    </span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501648"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501648"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="annot"><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span id="local-6989586621679501647"><span class="annot"><span class="annottext">a -&gt; Either e b
</span><a href="#local-6989586621679501647"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Either e b
</span><a href="#local-6989586621679501647"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501648"><span class="hs-identifier hs-var">r</span></a></span></span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="hs-comment">-- | Case analysis for the 'Either' type.</span><span>
</span><span id="line-160"></span><span class="hs-comment">-- If the value is @'Left' a@, apply the first function to @a@;</span><span>
</span><span id="line-161"></span><span class="hs-comment">-- if it is @'Right' b@, apply the second function to @b@.</span><span>
</span><span id="line-162"></span><span class="hs-comment">--</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-164"></span><span class="hs-comment">--</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- We create two values of type @'Either' 'String' 'Int'@, one using the</span><span>
</span><span id="line-166"></span><span class="hs-comment">-- 'Left' constructor and another using the 'Right' constructor. Then</span><span>
</span><span id="line-167"></span><span class="hs-comment">-- we apply \&quot;either\&quot; the 'Prelude.length' function (if we have a 'String')</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- or the \&quot;times-two\&quot; function (if we have an 'Int'):</span><span>
</span><span id="line-169"></span><span class="hs-comment">--</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- &gt;&gt;&gt; let s = Left &quot;foo&quot; :: Either String Int</span><span>
</span><span id="line-171"></span><span class="hs-comment">-- &gt;&gt;&gt; let n = Right 3 :: Either String Int</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- &gt;&gt;&gt; either length (*2) s</span><span>
</span><span id="line-173"></span><span class="hs-comment">-- 3</span><span>
</span><span id="line-174"></span><span class="hs-comment">-- &gt;&gt;&gt; either length (*2) n</span><span>
</span><span id="line-175"></span><span class="hs-comment">-- 6</span><span>
</span><span id="line-176"></span><span class="hs-comment">--</span><span>
</span><span id="line-177"></span><span id="local-6989586621679501836"><span id="local-6989586621679501837"><span id="local-6989586621679501838"><span class="annot"><a href="Data.Either.html#either"><span class="hs-identifier hs-type">either</span></a></span><span>                  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679501838"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679501837"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679501836"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679501837"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501838"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501836"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679501837"><span class="hs-identifier hs-type">c</span></a></span></span></span></span><span>
</span><span id="line-178"></span><span id="either"><span class="annot"><span class="annottext">either :: forall a c b. (a -&gt; c) -&gt; (b -&gt; c) -&gt; Either a b -&gt; c
</span><a href="Data.Either.html#either"><span class="hs-identifier hs-var hs-var">either</span></a></span></span><span> </span><span id="local-6989586621679501646"><span class="annot"><span class="annottext">a -&gt; c
</span><a href="#local-6989586621679501646"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="annot"><span class="annottext">b -&gt; c
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679501645"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501645"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">a -&gt; c
</span><a href="#local-6989586621679501646"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501645"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-179"></span><span class="annot"><a href="Data.Either.html#either"><span class="hs-identifier hs-var">either</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; c
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679501644"><span class="annot"><span class="annottext">b -&gt; c
</span><a href="#local-6989586621679501644"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501643"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501643"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">b -&gt; c
</span><a href="#local-6989586621679501644"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501643"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-180"></span><span>
</span><span id="line-181"></span><span>
</span><span id="line-182"></span><span class="hs-comment">-- | Extracts from a list of 'Either' all the 'Left' elements.</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- All the 'Left' elements are extracted in order.</span><span>
</span><span id="line-184"></span><span class="hs-comment">--</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-188"></span><span class="hs-comment">--</span><span>
</span><span id="line-189"></span><span class="hs-comment">-- &gt;&gt;&gt; let list = [ Left &quot;foo&quot;, Right 3, Left &quot;bar&quot;, Right 7, Left &quot;baz&quot; ]</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- &gt;&gt;&gt; lefts list</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- [&quot;foo&quot;,&quot;bar&quot;,&quot;baz&quot;]</span><span>
</span><span id="line-192"></span><span class="hs-comment">--</span><span>
</span><span id="line-193"></span><span id="local-6989586621679501831"><span id="local-6989586621679501832"><span class="annot"><a href="Data.Either.html#lefts"><span class="hs-identifier hs-type">lefts</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501832"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501831"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679501832"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span></span><span>
</span><span id="line-194"></span><span id="lefts"><span class="annot"><span class="annottext">lefts :: forall a b. [Either a b] -&gt; [a]
</span><a href="Data.Either.html#lefts"><span class="hs-identifier hs-var hs-var">lefts</span></a></span></span><span> </span><span id="local-6989586621679501642"><span class="annot"><span class="annottext">[Either a b]
</span><a href="#local-6989586621679501642"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501641"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679501641"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501641"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Either a b]
</span><a href="#local-6989586621679501642"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-195"></span><span class="hs-pragma">{-# INLINEABLE</span><span> </span><span class="annot"><a href="Data.Either.html#lefts"><span class="hs-pragma hs-type">lefts</span></a></span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-comment">-- otherwise doesn't get an unfolding, see #13689</span><span>
</span><span id="line-196"></span><span>
</span><span id="line-197"></span><span class="hs-comment">-- | Extracts from a list of 'Either' all the 'Right' elements.</span><span>
</span><span id="line-198"></span><span class="hs-comment">-- All the 'Right' elements are extracted in order.</span><span>
</span><span id="line-199"></span><span class="hs-comment">--</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-201"></span><span class="hs-comment">--</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-203"></span><span class="hs-comment">--</span><span>
</span><span id="line-204"></span><span class="hs-comment">-- &gt;&gt;&gt; let list = [ Left &quot;foo&quot;, Right 3, Left &quot;bar&quot;, Right 7, Left &quot;baz&quot; ]</span><span>
</span><span id="line-205"></span><span class="hs-comment">-- &gt;&gt;&gt; rights list</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- [3,7]</span><span>
</span><span id="line-207"></span><span class="hs-comment">--</span><span>
</span><span id="line-208"></span><span id="local-6989586621679501827"><span id="local-6989586621679501828"><span class="annot"><a href="Data.Either.html#rights"><span class="hs-identifier hs-type">rights</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501828"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501827"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679501827"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span></span></span><span>
</span><span id="line-209"></span><span id="rights"><span class="annot"><span class="annottext">rights :: forall a b. [Either a b] -&gt; [b]
</span><a href="Data.Either.html#rights"><span class="hs-identifier hs-var hs-var">rights</span></a></span></span><span> </span><span id="local-6989586621679501640"><span class="annot"><span class="annottext">[Either a b]
</span><a href="#local-6989586621679501640"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501639"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501639"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501639"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Either a b]
</span><a href="#local-6989586621679501640"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-210"></span><span class="hs-pragma">{-# INLINEABLE</span><span> </span><span class="annot"><a href="Data.Either.html#rights"><span class="hs-pragma hs-type">rights</span></a></span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-comment">-- otherwise doesn't get an unfolding, see #13689</span><span>
</span><span id="line-211"></span><span>
</span><span id="line-212"></span><span class="hs-comment">-- | Partitions a list of 'Either' into two lists.</span><span>
</span><span id="line-213"></span><span class="hs-comment">-- All the 'Left' elements are extracted, in order, to the first</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- component of the output.  Similarly the 'Right' elements are extracted</span><span>
</span><span id="line-215"></span><span class="hs-comment">-- to the second component of the output.</span><span>
</span><span id="line-216"></span><span class="hs-comment">--</span><span>
</span><span id="line-217"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-218"></span><span class="hs-comment">--</span><span>
</span><span id="line-219"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-220"></span><span class="hs-comment">--</span><span>
</span><span id="line-221"></span><span class="hs-comment">-- &gt;&gt;&gt; let list = [ Left &quot;foo&quot;, Right 3, Left &quot;bar&quot;, Right 7, Left &quot;baz&quot; ]</span><span>
</span><span id="line-222"></span><span class="hs-comment">-- &gt;&gt;&gt; partitionEithers list</span><span>
</span><span id="line-223"></span><span class="hs-comment">-- ([&quot;foo&quot;,&quot;bar&quot;,&quot;baz&quot;],[3,7])</span><span>
</span><span id="line-224"></span><span class="hs-comment">--</span><span>
</span><span id="line-225"></span><span class="hs-comment">-- The pair returned by @'partitionEithers' x@ should be the same</span><span>
</span><span id="line-226"></span><span class="hs-comment">-- pair as @('lefts' x, 'rights' x)@:</span><span>
</span><span id="line-227"></span><span class="hs-comment">--</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- &gt;&gt;&gt; let list = [ Left &quot;foo&quot;, Right 3, Left &quot;bar&quot;, Right 7, Left &quot;baz&quot; ]</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- &gt;&gt;&gt; partitionEithers list == (lefts list, rights list)</span><span>
</span><span id="line-230"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-231"></span><span class="hs-comment">--</span><span>
</span><span id="line-232"></span><span id="local-6989586621679501823"><span id="local-6989586621679501824"><span class="annot"><a href="Data.Either.html#partitionEithers"><span class="hs-identifier hs-type">partitionEithers</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501824"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501823"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679501824"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679501823"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-233"></span><span id="partitionEithers"><span class="annot"><span class="annottext">partitionEithers :: forall a b. [Either a b] -&gt; ([a], [b])
</span><a href="Data.Either.html#partitionEithers"><span class="hs-identifier hs-var hs-var">partitionEithers</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Either a b -&gt; ([a], [b]) -&gt; ([a], [b]))
-&gt; ([a], [b]) -&gt; [Either a b] -&gt; ([a], [b])
forall a b. (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
</span><a href="GHC.Base.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a -&gt; ([a], [b]) -&gt; ([a], [b]))
-&gt; (b -&gt; ([a], [b]) -&gt; ([a], [b]))
-&gt; Either a b
-&gt; ([a], [b])
-&gt; ([a], [b])
forall a c b. (a -&gt; c) -&gt; (b -&gt; c) -&gt; Either a b -&gt; c
</span><a href="Data.Either.html#either"><span class="hs-identifier hs-var">either</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; ([a], [b]) -&gt; ([a], [b])
forall {a} {b}. a -&gt; ([a], b) -&gt; ([a], b)
</span><a href="#local-6989586621679501638"><span class="hs-identifier hs-var">left</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; ([a], [b]) -&gt; ([a], [b])
forall {a} {a}. a -&gt; (a, [a]) -&gt; (a, [a])
</span><a href="#local-6989586621679501637"><span class="hs-identifier hs-var">right</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-234"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-235"></span><span>  </span><span id="local-6989586621679501638"><span class="annot"><span class="annottext">left :: a -&gt; ([a], b) -&gt; ([a], b)
</span><a href="#local-6989586621679501638"><span class="hs-identifier hs-var hs-var">left</span></a></span></span><span>  </span><span id="local-6989586621679501636"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501636"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">~</span><span class="hs-special">(</span><span id="local-6989586621679501635"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679501635"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679501634"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501634"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501636"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679501635"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501634"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-236"></span><span>  </span><span id="local-6989586621679501637"><span class="annot"><span class="annottext">right :: a -&gt; (a, [a]) -&gt; (a, [a])
</span><a href="#local-6989586621679501637"><span class="hs-identifier hs-var hs-var">right</span></a></span></span><span> </span><span id="local-6989586621679501633"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501633"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">~</span><span class="hs-special">(</span><span id="local-6989586621679501632"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501632"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679501631"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679501631"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501632"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501633"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679501631"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span>
</span><span id="line-238"></span><span class="hs-comment">-- | Return `True` if the given value is a `Left`-value, `False` otherwise.</span><span>
</span><span id="line-239"></span><span class="hs-comment">--</span><span>
</span><span id="line-240"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-241"></span><span class="hs-comment">--</span><span>
</span><span id="line-242"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-243"></span><span class="hs-comment">--</span><span>
</span><span id="line-244"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-245"></span><span class="hs-comment">--</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- &gt;&gt;&gt; isLeft (Left &quot;foo&quot;)</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-248"></span><span class="hs-comment">-- &gt;&gt;&gt; isLeft (Right 3)</span><span>
</span><span id="line-249"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-250"></span><span class="hs-comment">--</span><span>
</span><span id="line-251"></span><span class="hs-comment">-- Assuming a 'Left' value signifies some sort of error, we can use</span><span>
</span><span id="line-252"></span><span class="hs-comment">-- 'isLeft' to write a very simple error-reporting function that does</span><span>
</span><span id="line-253"></span><span class="hs-comment">-- absolutely nothing in the case of success, and outputs \&quot;ERROR\&quot; if</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- any error occurred.</span><span>
</span><span id="line-255"></span><span class="hs-comment">--</span><span>
</span><span id="line-256"></span><span class="hs-comment">-- This example shows how 'isLeft' might be used to avoid pattern</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- matching when one does not care about the value contained in the</span><span>
</span><span id="line-258"></span><span class="hs-comment">-- constructor:</span><span>
</span><span id="line-259"></span><span class="hs-comment">--</span><span>
</span><span id="line-260"></span><span class="hs-comment">-- &gt;&gt;&gt; import Control.Monad ( when )</span><span>
</span><span id="line-261"></span><span class="hs-comment">-- &gt;&gt;&gt; let report e = when (isLeft e) $ putStrLn &quot;ERROR&quot;</span><span>
</span><span id="line-262"></span><span class="hs-comment">-- &gt;&gt;&gt; report (Right 1)</span><span>
</span><span id="line-263"></span><span class="hs-comment">-- &gt;&gt;&gt; report (Left &quot;parse error&quot;)</span><span>
</span><span id="line-264"></span><span class="hs-comment">-- ERROR</span><span>
</span><span id="line-265"></span><span class="hs-comment">--</span><span>
</span><span id="line-266"></span><span id="local-6989586621679501812"><span id="local-6989586621679501813"><span class="annot"><a href="Data.Either.html#isLeft"><span class="hs-identifier hs-type">isLeft</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501813"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501812"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span></span><span>
</span><span id="line-267"></span><span id="isLeft"><span class="annot"><span class="annottext">isLeft :: forall a b. Either a b -&gt; Bool
</span><a href="Data.Either.html#isLeft"><span class="hs-identifier hs-var hs-var">isLeft</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-268"></span><span class="annot"><a href="Data.Either.html#isLeft"><span class="hs-identifier hs-var">isLeft</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span class="hs-comment">-- | Return `True` if the given value is a `Right`-value, `False` otherwise.</span><span>
</span><span id="line-271"></span><span class="hs-comment">--</span><span>
</span><span id="line-272"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-273"></span><span class="hs-comment">--</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-275"></span><span class="hs-comment">--</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-277"></span><span class="hs-comment">--</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- &gt;&gt;&gt; isRight (Left &quot;foo&quot;)</span><span>
</span><span id="line-279"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- &gt;&gt;&gt; isRight (Right 3)</span><span>
</span><span id="line-281"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-282"></span><span class="hs-comment">--</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- Assuming a 'Left' value signifies some sort of error, we can use</span><span>
</span><span id="line-284"></span><span class="hs-comment">-- 'isRight' to write a very simple reporting function that only</span><span>
</span><span id="line-285"></span><span class="hs-comment">-- outputs \&quot;SUCCESS\&quot; when a computation has succeeded.</span><span>
</span><span id="line-286"></span><span class="hs-comment">--</span><span>
</span><span id="line-287"></span><span class="hs-comment">-- This example shows how 'isRight' might be used to avoid pattern</span><span>
</span><span id="line-288"></span><span class="hs-comment">-- matching when one does not care about the value contained in the</span><span>
</span><span id="line-289"></span><span class="hs-comment">-- constructor:</span><span>
</span><span id="line-290"></span><span class="hs-comment">--</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- &gt;&gt;&gt; import Control.Monad ( when )</span><span>
</span><span id="line-292"></span><span class="hs-comment">-- &gt;&gt;&gt; let report e = when (isRight e) $ putStrLn &quot;SUCCESS&quot;</span><span>
</span><span id="line-293"></span><span class="hs-comment">-- &gt;&gt;&gt; report (Left &quot;parse error&quot;)</span><span>
</span><span id="line-294"></span><span class="hs-comment">-- &gt;&gt;&gt; report (Right 1)</span><span>
</span><span id="line-295"></span><span class="hs-comment">-- SUCCESS</span><span>
</span><span id="line-296"></span><span class="hs-comment">--</span><span>
</span><span id="line-297"></span><span id="local-6989586621679501629"><span id="local-6989586621679501630"><span class="annot"><a href="Data.Either.html#isRight"><span class="hs-identifier hs-type">isRight</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501630"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501629"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span></span><span>
</span><span id="line-298"></span><span id="isRight"><span class="annot"><span class="annottext">isRight :: forall a b. Either a b -&gt; Bool
</span><a href="Data.Either.html#isRight"><span class="hs-identifier hs-var hs-var">isRight</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-299"></span><span class="annot"><a href="Data.Either.html#isRight"><span class="hs-identifier hs-var">isRight</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span class="hs-comment">-- | Return the contents of a 'Left'-value or a default value otherwise.</span><span>
</span><span id="line-302"></span><span class="hs-comment">--</span><span>
</span><span id="line-303"></span><span class="hs-comment">-- @since 4.10.0.0</span><span>
</span><span id="line-304"></span><span class="hs-comment">--</span><span>
</span><span id="line-305"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-306"></span><span class="hs-comment">--</span><span>
</span><span id="line-307"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-308"></span><span class="hs-comment">--</span><span>
</span><span id="line-309"></span><span class="hs-comment">-- &gt;&gt;&gt; fromLeft 1 (Left 3)</span><span>
</span><span id="line-310"></span><span class="hs-comment">-- 3</span><span>
</span><span id="line-311"></span><span class="hs-comment">-- &gt;&gt;&gt; fromLeft 1 (Right &quot;foo&quot;)</span><span>
</span><span id="line-312"></span><span class="hs-comment">-- 1</span><span>
</span><span id="line-313"></span><span class="hs-comment">--</span><span>
</span><span id="line-314"></span><span id="local-6989586621679501806"><span id="local-6989586621679501807"><span class="annot"><a href="Data.Either.html#fromLeft"><span class="hs-identifier hs-type">fromLeft</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679501807"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501807"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501806"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679501807"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-315"></span><span id="fromLeft"><span class="annot"><span class="annottext">fromLeft :: forall a b. a -&gt; Either a b -&gt; a
</span><a href="Data.Either.html#fromLeft"><span class="hs-identifier hs-var hs-var">fromLeft</span></a></span></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679501628"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501628"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501628"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-316"></span><span class="annot"><a href="Data.Either.html#fromLeft"><span class="hs-identifier hs-var">fromLeft</span></a></span><span> </span><span id="local-6989586621679501627"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501627"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="annot"><span class="annottext">Either a b
</span><span class="hs-identifier">_</span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679501627"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-317"></span><span>
</span><span id="line-318"></span><span class="hs-comment">-- | Return the contents of a 'Right'-value or a default value otherwise.</span><span>
</span><span id="line-319"></span><span class="hs-comment">--</span><span>
</span><span id="line-320"></span><span class="hs-comment">-- @since 4.10.0.0</span><span>
</span><span id="line-321"></span><span class="hs-comment">--</span><span>
</span><span id="line-322"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-323"></span><span class="hs-comment">--</span><span>
</span><span id="line-324"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-325"></span><span class="hs-comment">--</span><span>
</span><span id="line-326"></span><span class="hs-comment">-- &gt;&gt;&gt; fromRight 1 (Right 3)</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- 3</span><span>
</span><span id="line-328"></span><span class="hs-comment">-- &gt;&gt;&gt; fromRight 1 (Left &quot;foo&quot;)</span><span>
</span><span id="line-329"></span><span class="hs-comment">-- 1</span><span>
</span><span id="line-330"></span><span class="hs-comment">--</span><span>
</span><span id="line-331"></span><span id="local-6989586621679501802"><span id="local-6989586621679501803"><span class="annot"><a href="Data.Either.html#fromRight"><span class="hs-identifier hs-type">fromRight</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679501803"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501802"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679501803"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679501803"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-332"></span><span id="fromRight"><span class="annot"><span class="annottext">fromRight :: forall b a. b -&gt; Either a b -&gt; b
</span><a href="Data.Either.html#fromRight"><span class="hs-identifier hs-var hs-var">fromRight</span></a></span></span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679501626"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501626"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501626"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-333"></span><span class="annot"><a href="Data.Either.html#fromRight"><span class="hs-identifier hs-var">fromRight</span></a></span><span> </span><span id="local-6989586621679501625"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501625"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="annot"><span class="annottext">Either a b
</span><span class="hs-identifier">_</span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679501625"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-334"></span><span>
</span><span id="line-335"></span><span class="hs-comment">{-
{--------------------------------------------------------------------
  Testing
--------------------------------------------------------------------}
prop_partitionEithers :: [Either Int Int] -&gt; Bool
prop_partitionEithers x =
  partitionEithers x == (lefts x, rights x)
-}</span><span>
</span><span id="line-343"></span></pre></body></html>